<?php

namespace app\user\logic;

use app\common\logic\InfiniteCatLogic;
use app\model\AbnormalType;

class AbnormalTypeLogic
{
    protected AbnormalType $model;

    public function __construct()
    {
        $this->model = new AbnormalType();
    }

    /**
     * @Description 下拉选择列表
     * @author: zj
     * @param array $param
     * @time 2024/03/25 14:41:45
     * @return array
     */
    public function selectList(array $param)
    {
        $query = $this->model->field('out_id as id,pid,name')
            ->where('delete_time', $this->model::IS_DELETE_NO);
        if ($param['name']) {
            $query->where('name', 'like', '%'.trim($param['name']).'%');
        }

        $list = $query->order('out_id', 'desc')
            ->select()
            ->toArray();
        if (!$list) {
            return [];
        }

        $logic = new InfiniteCatLogic();
        return $logic->dataToTree($list);
    }
}
